#ifndef _BURST_EVENT_H
#define _BURST_EVENT_H

#define BUS_IO_SLEEPING 0
#define BUS_IO_READING 1
#define BUS_IO_WRITING 2
#define BUS_IO_ACCEPTING 3
#define BUS_IO_CONNECTING 4
#define BUS_IO_ERROR 5
#define BUS_IO_SLIDING 6

typedef void bus_handle_event_t(struct bus_event *);
typedef struct bus_event bus_event_t;

typedef struct bus_io_sender {
	u8 buf_start[BUS_BUF_SIZE];
	u8 *bufptr;
	int remain;
} bus_io_sender_t;

typedef struct bus_io_object {
	int event;
	u8 buf_start[BUS_BUF_SIZE];
	u8 *bufptr;
	int len;
	struct list_head node;
} bus_io_object_t;

typedef struct bus_io_poll {
	int obj_count;
	struct list_head idle;
	struct list_head using_r;
	struct list_head using_w;
	bus_io_object_t *obj_using;
	bus_io_object_t rsv;
} bus_io_poll_t;

typedef struct bus_pipe {
	bus_event_t *to;
} bus_pipe_t;

struct bus_event {
	u_int sockfd;
	void *data;
	u_int type;
	u_int event;
	u_int status;
	union {
		bus_pipe_t pipe;
	};
	bus_io_poll_t io_object;
	bus_io_sender_t sender;
	bus_handle_event_t *handler;
	struct sockaddr_in sa;
	struct bus_event *father; /* It is used in accepting connection */
	struct list_head list;
};

#endif
